<%@ page import="dao.UserDao" %>
<%@ page import="entity.User" %><%--
  Created by IntelliJ IDEA.
  User: 20154
  Date: 2024/10/16
  Time: 14:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    //对login.jsp传递过来的数据进行校验，如果成功 则跳转到首页index.jsp
    //否则  回到登录页login.jsp
    //1.获得表单传递的参数
    String sname  = request.getParameter("username");
    String spwd   = request.getParameter("pwd");
    //2.进行验证
    //if(sname.equals("wei") && spwd.equals("111111"))
    User user  = new UserDao().login(sname,spwd); //!!!从数据库中进行比较
    if(user !=null)  //成功
    {
        //在web服务上发放一张有效凭证 只对当前浏览器有效
        session.setAttribute("loginUser",user); //!!!将用户对象保存到session

        response.sendRedirect("index.jsp");  //跳转到首页
    }else{
        response.sendRedirect("login.jsp");  //跳转到登录页
    }


%>
